package com.facebank.usersupport.controller;

import com.facebank.usersupport.model.DgutMessage;
import com.facebank.usersupport.model.RestModel;
import com.facebank.usersupport.service.IMallService;
import com.facebank.usersupport.util.TimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
public class MallController {
    @Autowired
    private IMallService mallService;

    @RequestMapping("/mall/up")
    public RestModel up(Integer id){ return mallService.up(id);}

    @RequestMapping("/mall/down")
    public RestModel down(Integer id){ return mallService.down(id); }

    @RequestMapping("/mall/cart")
    public RestModel cart(Long assId,Integer activityId,Integer num){ return mallService.cart(assId,activityId,num); }

    @RequestMapping("/mall/orderList")
    public RestModel orderList(@RequestParam(required = false, defaultValue = "1") int pageNo,
                               @RequestParam(required = false, defaultValue = "6") int length,
                               Long orderNo, Short routeType,Short status ,String starttime, String endtime){

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Long startTime = TimeUtil.StringToLong(starttime,sdf);
        Long endTime = TimeUtil.StringToLong(endtime,sdf);
        return mallService.orderList(pageNo,length,orderNo,routeType,status,startTime,endTime);};

    /**
     * 显示消息
     * @param session
     * @return
     */
    @RequestMapping("/mall/message")
    public RestModel message(HttpSession session){ return mallService.ahowMessage(); }

    /**
     * 添加信息
     * @param message
     * @param session
     * @return
     */
    @RequestMapping("/mall/add_message")
    public RestModel addMessage(DgutMessage message,HttpSession session){ return mallService.addMessage(message,session); }

    /**
     * 更新信息
     * @param dgutMessage
     * @param session
     * @return
     */
    @RequestMapping("/mall/update_message")
    public RestModel updateMessage(DgutMessage dgutMessage, HttpSession session){ return
            mallService.updateMessage(dgutMessage,session);
    }

    /**
     * 删除消息
     * @param messId
     * @param session
     * @return
     */
    @RequestMapping("/mall/delete_message")
    public RestModel deleteMessage(Long messId, HttpSession session){ return mallService.deleteMessage(messId); }

    /**
     * 查看消息详情
     * @param messId
     * @param session
     * @return
     */
    @RequestMapping("/mall/detail_message")
    public RestModel detailMessage(Long messId, HttpSession session){ return mallService.detailMessage(messId); }

    }

